/*
 * DC_MainFormView.java
 */

package dc_mainform;

import studentdata.*;
import java.io.*;
import java.util.*;
import java.text.SimpleDateFormat;
import org.jdesktop.application.Action;
import org.jdesktop.application.ResourceMap;
import org.jdesktop.application.SingleFrameApplication;
import org.jdesktop.application.FrameView;
import org.jdesktop.application.TaskMonitor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.AbstractButton;
import javax.swing.Timer;
import javax.swing.Icon;
import javax.swing.JDialog;
import javax.swing.JFrame;

/**
 * The application's main frame.
 */
public class DC_MainFormView extends FrameView {

    public DC_MainFormView(SingleFrameApplication app) {
        super(app);

        initComponents();

        // status bar initialization - message timeout, idle icon and busy animation, etc
        ResourceMap resourceMap = getResourceMap();
        int messageTimeout = resourceMap.getInteger("StatusBar.messageTimeout");
        messageTimer = new Timer(messageTimeout, new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                statusMessageLabel.setText("");
            }
        });
        messageTimer.setRepeats(false);
        int busyAnimationRate = resourceMap.getInteger("StatusBar.busyAnimationRate");
        for (int i = 0; i < busyIcons.length; i++) {
            busyIcons[i] = resourceMap.getIcon("StatusBar.busyIcons[" + i + "]");
        }
        busyIconTimer = new Timer(busyAnimationRate, new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                busyIconIndex = (busyIconIndex + 1) % busyIcons.length;
                statusAnimationLabel.setIcon(busyIcons[busyIconIndex]);
            }
        });
        idleIcon = resourceMap.getIcon("StatusBar.idleIcon");
        statusAnimationLabel.setIcon(idleIcon);
        progressBar.setVisible(false);

        // connecting action tasks to status bar via TaskMonitor
        TaskMonitor taskMonitor = new TaskMonitor(getApplication().getContext());
        taskMonitor.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                String propertyName = evt.getPropertyName();
                if ("started".equals(propertyName)) {
                    if (!busyIconTimer.isRunning()) {
                        statusAnimationLabel.setIcon(busyIcons[0]);
                        busyIconIndex = 0;
                        busyIconTimer.start();
                    }
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(true);
                } else if ("done".equals(propertyName)) {
                    busyIconTimer.stop();
                    statusAnimationLabel.setIcon(idleIcon);
                    progressBar.setVisible(false);
                    progressBar.setValue(0);
                } else if ("message".equals(propertyName)) {
                    String text = (String)(evt.getNewValue());
                    statusMessageLabel.setText((text == null) ? "" : text);
                    messageTimer.restart();
                } else if ("progress".equals(propertyName)) {
                    int value = (Integer)(evt.getNewValue());
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(false);
                    progressBar.setValue(value);
                }
            }
        });
        //show blocking box with login information
        LoginJDialog loginDlg = new LoginJDialog(this.getFrame(), true);
        loginDlg.setVisible(true);
        name = loginDlg.getName();
        surname = loginDlg.getSurname();
        loginDlg.dispose();
    }

    @Action
    public void showAboutBox() {
        if (aboutBox == null) {
            JFrame mainFrame = DC_MainFormApp.getApplication().getMainFrame();
            aboutBox = new DC_MainFormAboutBox(mainFrame);
            aboutBox.setLocationRelativeTo(mainFrame);
        }
        DC_MainFormApp.getApplication().show(aboutBox);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        mainPanel = new javax.swing.JPanel();
        nameLabel = new javax.swing.JLabel();
        surnameLabel = new javax.swing.JLabel();
        peselLabel = new javax.swing.JLabel();
        facultyLabel = new javax.swing.JLabel();
        dormitoryCodeLabel = new javax.swing.JLabel();
        roomNumberLabel = new javax.swing.JLabel();
        nameTextField = new javax.swing.JTextField();
        surnameTextField = new javax.swing.JTextField();
        peselTextField = new javax.swing.JTextField();
        facultyTextField = new javax.swing.JTextField();
        dormitoryCodeTextField = new javax.swing.JTextField();
        roomNumberTextField = new javax.swing.JTextField();
        saveButton = new javax.swing.JButton();
        lampCheckBox = new javax.swing.JCheckBox();
        blanketCheckBox = new javax.swing.JCheckBox();
        phoneCheckBox = new javax.swing.JCheckBox();
        beddingCheckBox = new javax.swing.JCheckBox();
        MACNumberTextField = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        menuBar = new javax.swing.JMenuBar();
        javax.swing.JMenu fileMenu = new javax.swing.JMenu();
        openMenuItem = new javax.swing.JMenuItem();
        newMenuItem = new javax.swing.JMenuItem();
        javax.swing.JMenuItem exitMenuItem = new javax.swing.JMenuItem();
        javax.swing.JMenu helpMenu = new javax.swing.JMenu();
        javax.swing.JMenuItem aboutMenuItem = new javax.swing.JMenuItem();
        statusPanel = new javax.swing.JPanel();
        javax.swing.JSeparator statusPanelSeparator = new javax.swing.JSeparator();
        statusMessageLabel = new javax.swing.JLabel();
        statusAnimationLabel = new javax.swing.JLabel();
        progressBar = new javax.swing.JProgressBar();

        mainPanel.setName("mainPanel"); // NOI18N
        mainPanel.setPreferredSize(new java.awt.Dimension(310, 300));

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(dc_mainform.DC_MainFormApp.class).getContext().getResourceMap(DC_MainFormView.class);
        nameLabel.setText(resourceMap.getString("nameLabel.text")); // NOI18N
        nameLabel.setName("nameLabel"); // NOI18N

        surnameLabel.setText(resourceMap.getString("surnameLabel.text")); // NOI18N
        surnameLabel.setName("surnameLabel"); // NOI18N

        peselLabel.setText(resourceMap.getString("peselLabel.text")); // NOI18N
        peselLabel.setName("peselLabel"); // NOI18N

        facultyLabel.setText(resourceMap.getString("facultyLabel.text")); // NOI18N
        facultyLabel.setName("facultyLabel"); // NOI18N

        dormitoryCodeLabel.setText(resourceMap.getString("dormitoryCodeLabel.text")); // NOI18N
        dormitoryCodeLabel.setName("dormitoryCodeLabel"); // NOI18N

        roomNumberLabel.setText(resourceMap.getString("roomNumberLabel.text")); // NOI18N
        roomNumberLabel.setName("roomNumberLabel"); // NOI18N

        nameTextField.setText(resourceMap.getString("nameTextField.text")); // NOI18N
        nameTextField.setName("nameTextField"); // NOI18N

        surnameTextField.setText(resourceMap.getString("surnameTextField.text")); // NOI18N
        surnameTextField.setName("surnameTextField"); // NOI18N

        peselTextField.setText(resourceMap.getString("peselTextField.text")); // NOI18N
        peselTextField.setName("peselTextField"); // NOI18N

        facultyTextField.setText(resourceMap.getString("facultyTextField.text")); // NOI18N
        facultyTextField.setName("facultyTextField"); // NOI18N

        dormitoryCodeTextField.setText(resourceMap.getString("dormitoryCodeTextField.text")); // NOI18N
        dormitoryCodeTextField.setName("dormitoryCodeTextField"); // NOI18N

        roomNumberTextField.setText(resourceMap.getString("roomNumberTextField.text")); // NOI18N
        roomNumberTextField.setName("roomNumberTextField"); // NOI18N

        saveButton.setText(resourceMap.getString("saveButton.text")); // NOI18N
        saveButton.setName("saveButton"); // NOI18N
        saveButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveButtonActionPerformed(evt);
            }
        });

        lampCheckBox.setText(resourceMap.getString("lampCheckBox.text")); // NOI18N
        lampCheckBox.setName("lampCheckBox"); // NOI18N
        lampCheckBox.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                lampCheckBoxStateChanged(evt);
            }
        });

        blanketCheckBox.setText(resourceMap.getString("blanketCheckBox.text")); // NOI18N
        blanketCheckBox.setName("blanketCheckBox"); // NOI18N
        blanketCheckBox.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                blanketCheckBoxStateChanged(evt);
            }
        });

        phoneCheckBox.setText(resourceMap.getString("phoneCheckBox.text")); // NOI18N
        phoneCheckBox.setName("phoneCheckBox"); // NOI18N
        phoneCheckBox.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                phoneCheckBoxStateChanged(evt);
            }
        });

        beddingCheckBox.setText(resourceMap.getString("beddingCheckBox.text")); // NOI18N
        beddingCheckBox.setName("beddingCheckBox"); // NOI18N
        beddingCheckBox.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                beddingCheckBoxStateChanged(evt);
            }
        });

        MACNumberTextField.setText(resourceMap.getString("MACNumberTextField.text")); // NOI18N
        MACNumberTextField.setName("MACNumberTextField"); // NOI18N

        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
        mainPanel.setLayout(mainPanelLayout);
        mainPanelLayout.setHorizontalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addGap(43, 43, 43)
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(roomNumberLabel)
                    .addComponent(nameLabel)
                    .addComponent(peselLabel)
                    .addComponent(facultyLabel)
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addComponent(surnameLabel)
                        .addGap(1, 1, 1))
                    .addComponent(dormitoryCodeLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(facultyTextField)
                            .addComponent(peselTextField)
                            .addComponent(surnameTextField)
                            .addComponent(nameTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 187, Short.MAX_VALUE))
                        .addContainerGap(13, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup()
                        .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(roomNumberTextField, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 91, Short.MAX_VALUE)
                            .addComponent(dormitoryCodeTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 91, Short.MAX_VALUE))
                        .addGap(116, 116, 116))))
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lampCheckBox)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(blanketCheckBox)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(phoneCheckBox)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(beddingCheckBox)
                .addContainerGap(85, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup()
                .addGap(64, 64, 64)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(MACNumberTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 199, Short.MAX_VALUE)
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup()
                .addContainerGap(124, Short.MAX_VALUE)
                .addComponent(saveButton)
                .addGap(114, 114, 114))
        );
        mainPanelLayout.setVerticalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(nameLabel)
                    .addComponent(nameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(surnameLabel)
                    .addComponent(surnameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(peselLabel)
                    .addComponent(peselTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(facultyTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(facultyLabel))
                .addGap(18, 18, 18)
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(dormitoryCodeTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(dormitoryCodeLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(roomNumberLabel)
                    .addComponent(roomNumberTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lampCheckBox)
                    .addComponent(blanketCheckBox)
                    .addComponent(phoneCheckBox)
                    .addComponent(beddingCheckBox))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(MACNumberTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(saveButton)
                .addContainerGap(25, Short.MAX_VALUE))
        );

        menuBar.setName("menuBar"); // NOI18N

        fileMenu.setText(resourceMap.getString("fileMenu.text")); // NOI18N
        fileMenu.setName("fileMenu"); // NOI18N

        openMenuItem.setText(resourceMap.getString("openMenuItem.text")); // NOI18N
        openMenuItem.setName("openMenuItem"); // NOI18N
        openMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                openMenuItemActionPerformed(evt);
            }
        });
        fileMenu.add(openMenuItem);

        newMenuItem.setText(resourceMap.getString("newMenuItem.text")); // NOI18N
        newMenuItem.setName("newMenuItem"); // NOI18N
        newMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                newMenuItemActionPerformed(evt);
            }
        });
        fileMenu.add(newMenuItem);

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(dc_mainform.DC_MainFormApp.class).getContext().getActionMap(DC_MainFormView.class, this);
        exitMenuItem.setAction(actionMap.get("quit")); // NOI18N
        exitMenuItem.setName("exitMenuItem"); // NOI18N
        fileMenu.add(exitMenuItem);

        menuBar.add(fileMenu);

        helpMenu.setText(resourceMap.getString("helpMenu.text")); // NOI18N
        helpMenu.setName("helpMenu"); // NOI18N

        aboutMenuItem.setAction(actionMap.get("showAboutBox")); // NOI18N
        aboutMenuItem.setName("aboutMenuItem"); // NOI18N
        helpMenu.add(aboutMenuItem);

        menuBar.add(helpMenu);

        statusPanel.setName("statusPanel"); // NOI18N

        statusPanelSeparator.setName("statusPanelSeparator"); // NOI18N

        statusMessageLabel.setName("statusMessageLabel"); // NOI18N

        statusAnimationLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        statusAnimationLabel.setName("statusAnimationLabel"); // NOI18N

        progressBar.setName("progressBar"); // NOI18N

        javax.swing.GroupLayout statusPanelLayout = new javax.swing.GroupLayout(statusPanel);
        statusPanel.setLayout(statusPanelLayout);
        statusPanelLayout.setHorizontalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(statusPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(statusMessageLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 276, Short.MAX_VALUE)
                .addComponent(statusAnimationLabel)
                .addContainerGap())
            .addComponent(statusPanelSeparator, javax.swing.GroupLayout.DEFAULT_SIZE, 296, Short.MAX_VALUE)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, statusPanelLayout.createSequentialGroup()
                .addContainerGap(136, Short.MAX_VALUE)
                .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        statusPanelLayout.setVerticalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, statusPanelLayout.createSequentialGroup()
                .addGap(11, 11, 11)
                .addComponent(statusPanelSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(statusPanelLayout.createSequentialGroup()
                        .addGroup(statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(statusMessageLabel)
                            .addComponent(statusAnimationLabel))
                        .addGap(11, 11, 11))
                    .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
        );

        setComponent(mainPanel);
        setMenuBar(menuBar);
        setStatusBar(statusPanel);
    }// </editor-fold>//GEN-END:initComponents

    private void openMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_openMenuItemActionPerformed
        OpenJDialog openDlg = new OpenJDialog(null, true);
        openDlg.setVisible(true);

        loadedStudent = openDlg.getStudent();
        //and destroy
        openDlg.dispose();

        //set the student's data
        this.nameTextField.setEnabled(true);
        this.nameTextField.setText(loadedStudent.getName());
        this.surnameTextField.setEnabled(true);
        this.surnameTextField.setText(loadedStudent.getSurname());
        this.peselTextField.setEnabled(true);
        this.peselTextField.setText(loadedStudent.getPeselNumber());
        this.facultyTextField.setEnabled(true);
        this.facultyTextField.setText(loadedStudent.getFaculty());
        this.dormitoryCodeTextField.setEnabled(true);
        this.dormitoryCodeTextField.setText(loadedStudent.getDormitoryCode());
        this.roomNumberTextField.setEnabled(true);
        this.roomNumberTextField.setText(loadedStudent.getRoomNumber());

        this.lampCheckBox.setEnabled(true);
        this.lampCheckBox.setSelected(loadedStudent.isLamp());
        this.blanketCheckBox.setEnabled(true);
        this.blanketCheckBox.setSelected(loadedStudent.isBlanket());
        this.phoneCheckBox.setEnabled(true);
        this.phoneCheckBox.setSelected(loadedStudent.isPhone());
        this.beddingCheckBox.setEnabled(true);
        this.beddingCheckBox.setSelected(loadedStudent.isBedding());
        
        this.MACNumberTextField.setEnabled(true);
        this.MACNumberTextField.setText(loadedStudent.getMacNumber());


    }//GEN-LAST:event_openMenuItemActionPerformed

    private void newMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newMenuItemActionPerformed
        //create dialog
        NewJDialog newDlg = new NewJDialog(this.getFrame(), true);
        //show it
        newDlg.setVisible(true);
        //when it returns, get the student
        loadedStudent = newDlg.getStudent();
        //and destroy
        newDlg.dispose();

        //set the student's data
        this.nameTextField.setEnabled(true);
        this.nameTextField.setText(loadedStudent.getName());
        this.surnameTextField.setEnabled(true);
        this.surnameTextField.setText(loadedStudent.getSurname());

        //enable rest of the fields
        this.peselTextField.setEnabled(true);
        this.facultyTextField.setEnabled(true);
        this.dormitoryCodeTextField.setEnabled(true);
        this.roomNumberTextField.setEnabled(true);
        this.lampCheckBox.setEnabled(true);
        this.lampCheckBox.setSelected(false);
        this.blanketCheckBox.setEnabled(true);
        this.blanketCheckBox.setSelected(false);
        this.phoneCheckBox.setEnabled(true);
        this.phoneCheckBox.setSelected(false);
        this.beddingCheckBox.setEnabled(true);
        this.beddingCheckBox.setSelected(false);
        this.MACNumberTextField.setEditable(true);

    }//GEN-LAST:event_newMenuItemActionPerformed

    private void saveButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveButtonActionPerformed
        //update data from form fields
        loadedStudent.setName(this.nameTextField.getText());
        loadedStudent.setSurname(this.surnameTextField.getText());
        loadedStudent.setPeselNumber(this.peselTextField.getText());
        loadedStudent.setFaculty(this.facultyTextField.getText());
        loadedStudent.setDormitoryCode(this.dormitoryCodeTextField.getText());
        loadedStudent.setRoomNumber(this.roomNumberTextField.getText());
        loadedStudent.setMacNumber(this.MACNumberTextField.getText());

        Vector workflow = loadedStudent.getWorkflow();
        workflow.clear();
        WorkflowNode node = new WorkflowNode();
        node.fromID = Student.workIDs.ID_NONE;
        node.recipientID = Student.workIDs.ID_MANAGER;
        node.toID = Student.workIDs.ID_RECEPTIONIST;

        node.recipientName = name + " " + surname;
        node.sendDate = getCurrentDate();
        workflow.add(node);
        try{
            loadedStudent.writeToXML(loadedStudent.createFileName());
        }catch(IOException e)
        {
            System.out.println("Error during writing file " + loadedStudent.createFileName());
        }
    }//GEN-LAST:event_saveButtonActionPerformed

    private void lampCheckBoxStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_lampCheckBoxStateChanged
        // TODO add your handling code here:
        AbstractButton abstractButton = (AbstractButton)evt.getSource();
        boolean selected = abstractButton.getModel().isSelected();
        if(loadedStudent != null){
            loadedStudent.setLamp(selected);
            //System.out.println("lamp = "+loadedStudent.isLamp());
        }
    }//GEN-LAST:event_lampCheckBoxStateChanged

    private void blanketCheckBoxStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_blanketCheckBoxStateChanged
        // TODO add your handling code here:
        AbstractButton abstractButton = (AbstractButton)evt.getSource();
        boolean selected = abstractButton.getModel().isSelected();
        if(loadedStudent != null){
            loadedStudent.setBlanket(selected);
            //System.out.println("blanket = "+loadedStudent.isBlanket());
        }
    }//GEN-LAST:event_blanketCheckBoxStateChanged

    private void phoneCheckBoxStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_phoneCheckBoxStateChanged
        // TODO add your handling code here:
        AbstractButton abstractButton = (AbstractButton)evt.getSource();
        boolean selected = abstractButton.getModel().isSelected();
        if(loadedStudent != null){
            loadedStudent.setPhone(selected);
            //System.out.println("phone = "+loadedStudent.isPhone());
        }
    }//GEN-LAST:event_phoneCheckBoxStateChanged

    private void beddingCheckBoxStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_beddingCheckBoxStateChanged
        // TODO add your handling code here:
        AbstractButton abstractButton = (AbstractButton)evt.getSource();
        boolean selected = abstractButton.getModel().isSelected();
        if(loadedStudent != null){
            loadedStudent.setBedding(selected);
            //System.out.println("bedding = "+loadedStudent.isBedding());
        }
    }//GEN-LAST:event_beddingCheckBoxStateChanged

    public static String getCurrentDate()
    {
        String DATE_FORMAT_NOW = "yyyy-MM-dd";
        
        Calendar cal = Calendar.getInstance();
        SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_NOW);
        return sdf.format(cal.getTime());
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField MACNumberTextField;
    private javax.swing.JCheckBox beddingCheckBox;
    private javax.swing.JCheckBox blanketCheckBox;
    private javax.swing.JLabel dormitoryCodeLabel;
    private javax.swing.JTextField dormitoryCodeTextField;
    private javax.swing.JLabel facultyLabel;
    private javax.swing.JTextField facultyTextField;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JCheckBox lampCheckBox;
    private javax.swing.JPanel mainPanel;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JLabel nameLabel;
    private javax.swing.JTextField nameTextField;
    private javax.swing.JMenuItem newMenuItem;
    private javax.swing.JMenuItem openMenuItem;
    private javax.swing.JLabel peselLabel;
    private javax.swing.JTextField peselTextField;
    private javax.swing.JCheckBox phoneCheckBox;
    private javax.swing.JProgressBar progressBar;
    private javax.swing.JLabel roomNumberLabel;
    private javax.swing.JTextField roomNumberTextField;
    private javax.swing.JButton saveButton;
    private javax.swing.JLabel statusAnimationLabel;
    private javax.swing.JLabel statusMessageLabel;
    private javax.swing.JPanel statusPanel;
    private javax.swing.JLabel surnameLabel;
    private javax.swing.JTextField surnameTextField;
    // End of variables declaration//GEN-END:variables

    private final Timer messageTimer;
    private final Timer busyIconTimer;
    private final Icon idleIcon;
    private final Icon[] busyIcons = new Icon[15];
    private int busyIconIndex = 0;
    private Student loadedStudent = null;

    //user personal data
    private String name;
    private String surname;

    private JDialog aboutBox;
}
